<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "form_info".
 *
 * @property int $id
 * @property int $user_id
 * @property string $name 姓名
 * @property string $phone 手机号
 * @property string $company_name 企业
 * @property string $service_type 服务类型
 * @property int $voltage_level 电压等级
 * @property int $operation_type 运维方式
 * @property int $company_sg 施工单位
 * @property int $is_read
 * @property string $form_type
 * @property int $status
 * @property int $created_at
 */
class FormInfo extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'form_info';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id', 'voltage_level', 'operation_type', 'company_sg', 'install_at', 'is_read', 'status', 'created_at'], 'integer'],
            [['name', 'phone', 'company_name', 'service_type', 'company_sg_name', 'area_info', 'address', 'lng', 'lat', 'province', 'city', 'area', 'address_detail', 'specs_type'], 'string', 'max' => 255],
            [['form_type'], 'string', 'max' => 32],
            [['total_money'], 'number'],
            [['content', 'form_desc', 'form_img', 'content_json', 'capacity'], 'string'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'name' => 'Name',
            'phone' => 'Phone',
            'company_name' => 'Company Name',
            'service_type' => 'Service Type',
            'voltage_level' => 'Voltage Level',
            'operation_type' => 'Operation Type',
            'company_sg' => 'Company Sg',
            'is_read' => 'Is Read',
            'form_type' => 'Form Type',
            'status' => 'Status',
            'created_at' => 'Created At',
        ];
    }

    public function getUser(){
        return $this->hasOne(User::class, ['id' => 'user_id']);
    }

    public function getVoltage(){
        return $this->hasOne(FormTag::class, ['id' => 'voltage_level']);
    }

    public function getCompany(){
        return $this->hasOne(Repair::class, ['id' => 'company_sg']);
    }

    public function getType(){
        return $this->hasOne(FormType::class, ['code' => 'form_type']);
    }

    public function getCompanyWt(){
        return $this->hasOne(CompanyWt::class, ['id' => 'company_wt']);
    }
}
